import { Config } from "../../src/config/Config";
import { DbConfig } from "../../src/config/DbConfig";
import { Logger } from "../../src/engine/utils/Logger";
import { MysqlClient } from "../../src/engine/utils/MySqlClient";
import { MysqlManager } from "../../src/engine/utils/MysqlManager";

export class ResourceHistoryDao {

    public static DB_NAME: string = DbConfig.Db_Name.db_laoyou;

    private static getDbName() {
        // if (Config.environment == Config.EnvironmentType.yueyouhui) {
        //     return DbConfig.Db_Name.db_yuxiaxie2
        // } 
        // else if (Config.environment == Config.EnvironmentType.xj) {
        //     return DbConfig.Db_Name.db_yuxiaxie2
        // }
        // else if(Config.environment == Config.EnvironmentType.Jk){
        //     return DbConfig.Db_Name.db_yuxiaxie3
        // }
        // else if(Config.environment == Config.EnvironmentType.chaoyou){
        //     return DbConfig.Db_Name.db_yuxiaxie_chaoyu
        // }
        // else {
            return DbConfig.Db_Name.db_laoyou
        // }
    }


    public static async get_resource_history(startTime: number, endTime: number, charge_id: number) {
        let client: MysqlClient = await MysqlManager.instance.getDb(this.getDbName());
        let sql: string = "select  * from  t_resource_history  where time >= ? and time <= ?"
        let sqlParams = [startTime, endTime];
        let results = await client.queryPromise(sql, sqlParams);
        if (charge_id != 0) {
            sql += " and charge_id=" + charge_id
        }

        Logger.log("get_resource_history=", sql, sqlParams, results)
        if (results && results.length > 0) {
            return results
        } else {
            return []
        }
    }
}